<?php

class Silk_Tms_Adminhtml_RegionController extends Mage_Adminhtml_Controller_Action
{

	protected function _initAction()
	{
		$this->loadLayout()->_setActiveMenu("tms/region")->_addBreadcrumb(Mage::helper("adminhtml")->__("分拣区域管理"),Mage::helper("adminhtml")->__("分拣区域管理"));
		
		return $this;
	}

	protected function _isAllowed()
	{
		return Mage::getSingleton('admin/session')->isAllowed('sales/region');
	}

	
	public function indexAction()
	{
		$this->loadLayout();
	    $this->renderLayout();
	}

	public function editAction(){
		$id = $this->getRequest()->getParam('id');
		$model = Mage::getModel("tms/region")->load($id);
		if($model && $model->getId()){
			Mage::register("region_data", $model);
		}
		$this->loadLayout();
	    $this->renderLayout();
		
	}

	public function saveAction(){
		$data =$this->getRequest()->getPost();
		$model = Mage::getModel("tms/region")
			   ->addData($data)
			   ->setId($this->getRequest()->getParam("id"));
		try{
			$model->save();
		}catch(Exception $e){
			Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
		}
		$this->_redirect('*/*/');
	}

	public function massRemoveAction(){
		try {
			$ids = $this->getRequest()->getPost('ids', array());
			foreach ($ids as $id) {
				$model = Mage::getModel("tms/region");
				$model->setId($id)->delete();  
			}
			Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("已删除！"));
		}
		catch (Exception $e) {
			Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
		}
		$this->_redirect('*/*/');
	}

	
}
